import 'package:flutter/material.dart';

import '../controller/comic/read_controller.dart';

class ChapterSettingWidget extends StatefulWidget {
  final ReadController controller;

  ChapterSettingWidget(this.controller);

  @override
  State<StatefulWidget> createState() => _chapterSettingWidget();
}

class _chapterSettingWidget extends State<ChapterSettingWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: ListView(
        children: [
          GestureDetector(
            onTapDown: (TapDownDetails details) {
              showMenu(
                context: context,
                position: RelativeRect.fromLTRB(
                  details.globalPosition.dx,
                  details.globalPosition.dy,
                  details.globalPosition.dx + 1,
                  details.globalPosition.dy + 1,
                ),
                items: [
                  PopupMenuItem(
                    value: 'fill',
                    child: Text('自适应拉伸'),
                  ),
                  PopupMenuItem(
                    value: 'fitWidth',
                    child: Text('宽度自适应'),
                  ),
                  PopupMenuItem(
                    value: 'none',
                    child: Text('原始大小'),
                  ),
                ],
              ).then((value) {
                BoxFit fit;
                switch (value) {
                  case "fill":
                    fit = BoxFit.fill;
                    break;
                  case "fitWidth":
                    fit = BoxFit.fitWidth;
                    break;
                  case "none":
                    fit = BoxFit.none;
                    break;
                  default:
                    return;
                }
                widget.controller.changePhotoBoxFit(fit);
              });
            },
            child: ListTile(
              title: Text("图片显示方式"),
              subtitle: Text("设置图片的显示方式"),
              leading: Icon(
                Icons.photo_album,
              ),
              trailing: Icon(
                Icons.chevron_right_rounded,
              ),
            ),
          ),
          GestureDetector(
            onTapDown: (TapDownDetails details) {
              showMenu(
                context: context,
                position: RelativeRect.fromLTRB(
                  details.globalPosition.dx,
                  details.globalPosition.dy,
                  details.globalPosition.dx + 1,
                  details.globalPosition.dy + 1,
                ),
                items: [
                  PopupMenuItem(
                    value: 'horizontal',
                    child: Text('左右滚动'),
                  ),
                  PopupMenuItem(
                    value: 'vertical',
                    child: Text('上下滚动'),
                  ),
                ],
              ).then((value) {
                Axis axis;
                switch (value) {
                  case "horizontal":
                    axis = Axis.horizontal;
                    break;
                  case "vertical":
                    axis = Axis.vertical;
                    break;
                  default:
                    return;
                }
                widget.controller.changeReadMethod(axis);
              });
            },
            child: ListTile(
              title: Text("阅读方式"),
              subtitle: Text("设置横向纵向阅读方式"),
              leading: Icon(
                Icons.view_array,
              ),
              trailing: Icon(
                Icons.chevron_right_rounded,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
